package com.sghd.charge.module.model;

import java.util.HashMap;
import java.util.Map;

/**
 * @author
 * 充值回应状态码
 */
public enum ChargeCode {

    /** 成功 */
    DONE(0, true, false, "成功"),
    /** 与游戏服通讯异常 */
    SOCKET_ERROR(-5, false, true, "与游戏服通讯异常"),
    /** 未知错误 */
    UNKNOWN_ERROR(-12, false, false, "未知错误"),
    /** 签名验证失败*/
    SIGN_ERROR(-10, false, false, "签名验证失败"),
    /** 渠道充值错误*/
    CHANNEL_TYPE_ERROR(-11, false, false, "充值渠道错误"),
    /** 订单不存在*/
    ORDER_NOT_FOUND(-13, false, false, "订单不存在"),
    /** 服务器不存在*/
    SERVER_NOT_FOUND(-14, false, false, "服务器不存在"),
    /** 服务器返回失败*/
    SERVER_RETURN_FAIL(-14, false, false, "服务器返回失败");
    private static final Map<Integer, ChargeCode> CODES = new HashMap<Integer, ChargeCode>(ChargeCode.values().length);

    static {
        for (ChargeCode code : ChargeCode.values()) {
            CODES.put(code.getValue(), code);
        }
    }

    /** 构造方法 */
    public static ChargeCode valueOf(int code) {
        ChargeCode result = CODES.get(code);
        if (result == null) {
            throw new IllegalArgumentException("无效的充值状态码:" + code);
        }
        return result;
    }

    /** 状态码值 */
    private final int value;
    /** 是否成功状态码 */
    private final boolean success;
    /** 是否需要重试 */
    private final boolean retry;
    /** 状态描述 */
    private final String description;

    private ChargeCode(int value, boolean success, boolean retry, String description) {
        this.value = value;
        this.retry = retry;
        this.success = success;
        this.description = description;
    }

    public int getValue() {
        return value;
    }

    public boolean isSuccess() {
        return success;
    }

    public boolean isRetry() {
        return retry;
    }

    public String getDescription() {
        return description;
    }

}
